/* eslint-disable*/

import Vue from 'vue'
import Vuex from 'vuex'
import VueRouter from 'vue-router'

import * as FastClick from 'fastclick'
import 'intersection-observer'
import App from './App'
import {
  routerConfig,
  routerBefore,
  routerAfter
} from './router'
import {
  BIND_UPLOADACTION,
  BIND_TOKEN,
  BIND_VIEWACTION
} from './store/mutation-types'
import storeConfig from './store'
import './styles/theme.styl'
import './styles/global.css'
import './styles/com-style'
import 'animate.css'
import plugins from './plugins'
import {
  build,
  test,
  dev,
  common
} from '../config'
import {
} from './store/mutation-types'
import VeeValidate from './validation'
import 'babel-polyfill'
import pcEvent from './plugins/pcEvent'
import {
  vLoading
} from 'vue-any-loading'
import util from './_util/install'
/* global MAN_VERSION */
const version = /* @echo MAN_VERSION */ MAN_VERSION
const bill = s => (s < 10 ? `0${s}` : `${s}`)
const format = now => {
  return `${now.getFullYear()}-${bill(now.getMonth() + 1)}-${bill(
    now.getDate()
  )} ${bill(now.getHours())}:${bill(now.getMinutes())}:${bill(now.getSeconds())}`
}

// config
const productMode = process.env.NODE_ENV === 'production'
const config = productMode === true ? (process.env.TEST === 'true' ? test : build) : dev


// use
Vue.directive('loading', vLoading)
Vue.use(Vuex)
Vue.use(VueRouter)
Vue.use(util)
Vue.use(plugins, {
  config
})
Vue.use(VeeValidate)

// vue config
Vue.config.productionTip = false
Vue.config.performance = true
FastClick.attach(document.body)

// store init
const store = new Vuex.Store(storeConfig)
store.commit(BIND_VIEWACTION, config.viewAction)
store.commit(BIND_UPLOADACTION, config.uploadAction)
store.commit(BIND_TOKEN, config.token)
// 其他配置

// router config
const router = new VueRouter(routerConfig)
router.beforeEach(routerBefore(Vue, store))
router.afterEach(routerAfter(Vue, store));


(async function () {
  await pcEvent(Vue, {
    config
  })
  new Vue({
    el: '#app',
    router,
    store,
    components: {
      App
    },
    template: '<App/>',
    data() {
      return {
        eventHub: new Vue()
      }
    },
    mounted() {
      window.addEventListener('scroll', () => {
        this.eventHub.$emit('scroll', window.scrollY)
      })
      document.addEventListener('touchstart', () => {
        this.eventHub.$emit('touch')
      })
    }
  })
})()
